package huawei.exam5;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/1/1
 */
public class HJ101 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int size = scanner.nextInt();
            List<Integer> integers = new ArrayList<>(size);
            for (int i = 0; i < size; i++) {
                integers.add(scanner.nextInt());
            }
            int sortFlag = scanner.nextInt();
            if (sortFlag == 0) {
                integers.stream().sorted().forEach(num -> {
                    System.out.print(num + " ");
                });
            } else if (sortFlag == 1){
                integers.stream().sorted(Comparator.reverseOrder()).forEach(num -> {
                    System.out.print(num + " ");
                });
            }
        }
    }
}
